package Day2025_02_21;

/**
 * 懒汉模式 (线程安全)
 */

public class SingletonLazy {
    private static volatile SingletonLazy instance = null;
    private SingletonLazy() {}
    public static SingletonLazy getInstance() {
        if (instance == null) {
            synchronized (SingletonLazy.class) {
                if (instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        SingletonLazy singletonLazy = SingletonLazy.getInstance();
        singletonLazy.getInstance();
    }
}
